class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head)
    {
        if(!head || !head->next) {
            return head;
        }
        ListNode* p = new ListNode(-1);
        p->next = head;
        ListNode* cur = p, * pre = head;
        while(pre) {
            bool isDupli = false;
            while(pre->next && pre->val == pre->next->val) {
                isDupli = true;
                pre = pre->next;
            }
            if(isDupli) {
                pre = pre->next;
                continue;
            }
            cur->next = pre;
            cur = cur->next;
            pre = pre->next;
        }
        cur->next = pre;
        return p->next;
    }
};
